package com.gitee.consumer.controller;


import com.gitee.bodboy.entities.order.Payment;
import com.gitee.bodboy.result.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName OrderController
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/12/11 10:14
 **/
@Slf4j
@RestController
@RequestMapping("/consumer")
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;


    /**
     * 这里成服务名称的时候   RestTemplate一定要添加注解 @LoadBalanced  不然找不到该服务
     */
    public static final String ORGIN_URL ="http://PAYMENT";

    @GetMapping("/payment/getOne/{id}")
    public CommonResult<Payment> getOne(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(ORGIN_URL + "/payment/selectOne?id=" + id ,CommonResult.class);
    }

    @GetMapping("/payment/save")
    public CommonResult<Payment> save(Payment payment){
        return restTemplate.postForObject(ORGIN_URL + "/payment/save" ,payment ,CommonResult.class);
    }

    @GetMapping("payment/test")
    public Object test(){
        return restTemplate.getForObject(ORGIN_URL + "/payment/discovery", Object.class);
    }

    @GetMapping("/payment/zipkin")
    public String zipkin(){
        return restTemplate.getForObject("/payment/zipkin",String.class);
    }
}
